package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

@Entity()
// @org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_LINKS")
@BatchSize(size = 20)
@Lazy(value = true)
// @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class OperationTaskLink extends BasicModel {

	public final static int LINKTYPE_FTS = 1; // 结束开始
	public final static int LINKTYPE_FTF = 2; // 结束结束
	public final static int LINKTYPE_STS = 3; // 开始开始
	public final static int LINKTYPE_STF = 4; // 开始结束

	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUE_ID")
	protected String uniqueId;

	@Column(name = "SUCCUID")
	protected String succOperationTaskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SUCCUID", insertable = false, updatable = false)
	protected OperationTask succOperationTask;

	@Column(name = "PREDUID")
	protected String predOperationTaskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PREDUID", insertable = false, updatable = false)
	protected OperationTask predOperationTask;

	@Column(name = "LINKQTY")
	protected Float linkQty;

	@Column(name = "LINKLAG")
	protected Integer linkLag;

	@Column(name = "LINKTYPE")
	protected Integer linkType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "PRIORITY", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'linktype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData linkTypeDesc;

	@Column(name = "DEPENDTYPE")
	protected String dependType = "0";
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "PRIORITY", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'dependtype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData dependTypeDesc;

	@Column(name = "LOCKLEVEL")
	protected Integer lockLevel;

	@Column(name = "LOCKEXPIREDATE")
	protected Date lockExpireDate;

	@Column(name = "ISINEFFECT")
	private Boolean effective;

	
	
	
	public Boolean getEffective() {
		return effective;
	}

	public void setEffective(Boolean effective) {
		this.effective = effective;
	}

	public String getSuccOperationTaskUid() {
		return succOperationTaskUid;
	}

	public void setSuccOperationTaskUid(String succOperationTaskUid) {
		this.succOperationTaskUid = succOperationTaskUid;
	}

	public OperationTask getSuccOperationTask() {
		return succOperationTask;
	}

	public void setSuccOperationTask(OperationTask succOperationTask) {
		this.succOperationTask = succOperationTask;
		this.succOperationTaskUid = (succOperationTask != null) ? succOperationTask.getUuid() : null;
	}

	public String getPredOperationTaskUid() {
		return predOperationTaskUid;
	}

	public void setPredOperationTaskUid(String predOperationTaskUid) {
		this.predOperationTaskUid = predOperationTaskUid;
	}

	public OperationTask getPredOperationTask() {
		return predOperationTask;
	}

	public void setPredOperationTask(OperationTask predOperationTask) {
		this.predOperationTask = predOperationTask;
		this.predOperationTaskUid = (predOperationTask != null) ? predOperationTask.getUuid() : null;

	}

	public Float getLinkQty() {
		return linkQty;
	}

	public void setLinkQty(Float linkQty) {
		this.linkQty = linkQty;
	}

	public Integer getLinkType() {
		return linkType;
	}

	public void setLinkType(Integer linkType) {
		this.linkType = linkType;
	}

	public String getDependType() {
		return dependType;
	}

	public void setDependType(String dependType) {
		this.dependType = dependType;
	}
	
	public TypesData getDependTypeDesc() {
		return dependTypeDesc;
	}

	public void setDependTypeDesc(TypesData dependTypeDesc) {
		this.dependTypeDesc = dependTypeDesc;
	}

	public Integer getLockLevel() {
		return lockLevel;
	}

	public void setLockLevel(Integer lockLevel) {
		this.lockLevel = lockLevel;
	}

	public Date getLockExpireDate() {
		return lockExpireDate;
	}

	public void setLockExpireDate(Date lockExpireDate) {
		this.lockExpireDate = lockExpireDate;
	}

	public Integer getLinkLag() {
		return linkLag;
	}

	public void setLinkLag(Integer linkLag) {
		this.linkLag = linkLag;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}
	
	public TypesData getLinkTypeDesc() {
		return linkTypeDesc;
	}

	public void setLinkTypeDesc(TypesData linkTypeDesc) {
		this.linkTypeDesc = linkTypeDesc;
	}



}
